App.filter('link', function () {
    return function (input) {
        var ret = input.replace(/^https?:\/\//,'');
        var result = 'http://' + input;

        return '<a href="' + result + '" target="_blank">' + ret + '</a>' ;
    };
});

App.filter('fixDateTime', function () {
    return function (input) {
        if(input){
            return input.replace(/T/gi, ' ');
        }
    };
});

App.filter('partition', function () {
    var part = function (arr, size) {
        if (0 === arr.length) return [];
        return [ arr.slice(0, size) ].concat(part(arr.slice(size), size));
    };
    return part;
});

App.filter('capitalize', function () {
    return function (input) {
        return _.capitalize(input);
    };
});

App.filter('humanFileSize', function () {
    return function (input) {
        return humanFileSize(input)
    };
});

App.filter('cashHistoryJoin', function () {
    return function (input) {
        var ret = '';
        angular.forEach(input, function (value, key) {
            ret += value.updated_on + ' ' + value.amount + '<br/>';
        });
        return ret;
    };
});

App.filter('invoiceHistoryJoin', function () {
    return function (input) {
        var ret = '';
        angular.forEach(input, function (value, key) {
            ret += value.updated_on + ' ' + value.amount + '<br/>';
        });
        return ret;
    };
});

App.filter('orderInfo', function () {
    return function (input, type_) {
        var ret = '';
        if (!angular.isArray(input) || input.length == 0){
           return '' ;
        }
        ret += '<table class="table table-striped table-bordered table-condensed">';
        ret += '    <thead>';
        ret += '    <tr>';
        ret += '        <th>#</th>';
        ret += '        <th>Qty</th>';
        ret += '        <th>Amount</th>';
        ret += '        <th>Created on</th>';
        ret += '    </tr>';
        ret += '    </thead>';
        ret += '    <tbody>';

        var i = 0;
        angular.forEach(input, function (value, key) {
            i++;
            if (i <= 10){
                ret += '<tr>';
                ret += '    <td>' + value.slug + '</td>';
                ret += '    <td>' + value.qty + '</td>';
                ret += '    <td>' + fixNumber(value.amount, 5) + '</td>';
                ret += '    <td>' + value.created_on + '</td>';
                ret += '</tr>';
            }
        });
        ret += '</tbody>';
        ret += '</table>';
        return ret;
    };
});

App.filter('countReplyByIds', function(){
    return function (Ids) {
        if(Ids){
            return Ids.split(',').length;
        }else{
            return 0;
        }
    }
});